<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
	String DRV = "org.mariadb.jdbc.Driver";
	String URL = "jdbc:mariadb://localhost:3306/jwj8508?user=jwj8508&password=123456";
	String sql = "select * from boardv4 where bdno = ?";
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
%>
<%
	String bdno = null;
	String title = null;
	String uid = null;
	String contents = null;
%>
<%
	bdno = request.getParameter("bdno");
	// 조회할 본문글 번호가 입력되지 않으면 자동으로 list.jsp로 이동시킴
	if (bdno == null) {
		response.sendRedirect("list.jsp");
	}
%>
<%
	try {
		Class.forName(DRV);
		conn = DriverManager.getConnection(URL);
		pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, bdno);
		rs = pstmt.executeQuery();
		
		if (rs.next()) {
			do {
				title = rs.getString("title");
				uid = rs.getString("uid");
				contents = rs.getString("contents");
				contents = contents.replace("<br />", "\r\n");
			} while (rs.next());
		} else {
			// 입력한 본문글 번호가 boardv4에 존재하지 않으면 자동으로 list.jsp로 이동시킴
			try {response.sendRedirect("list.jsp");} catch(Exception e){}
		}
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		if (rs!=null)try{rs.close();}catch(Exception e){}
		if (pstmt!=null)try{pstmt.close();}catch(Exception e){}
		if (conn!=null)try{conn.close();}catch(Exception e){}
	}
%>
<!DOCTYPE html>
<html lang="ko">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<title>JSP 프로젝트 v1</title>
		<link type="text/css" href="../css/layout.css" rel="stylesheet" />
		<style type="text/css">			
			#content { width: 75%; margin: 0 auto; }
			label { font-weight: bold; display: inline-block;
				width: 15%; text-align: right; margin: 0 10px 10px 0; }
			#txta { width: 80%; height: 350px; resize: none; }
			.dragup { vertical-align: top; }
			button { margin: 10px; }
		</style>		
	</head>
	<body>
		<div>
			<h1>JSP 프로젝트 v1</h1> <!-- 제목 -->
			<ul id="nav">
				<li><a href="../index.jsp">Home</a></li>
				<li><a href="../member/join.html">회원가입</a></li>
				<li><a href="../member/login.html">로그인</a></li>
				<li><a href="list.html">게시판</a></li>
				<li><a href="../member/myinfo.html">회원정보</a></li>
			</ul> <!-- 상단메뉴 -->
			<hr />
		</div> <!-- header -->
		
		<div id="content">
			<h2>게시판 수정하기</h2>
			<form name="b" method="post" action="updateok.jsp">
				<div><label for="title">제목</label><input type="text" name="title" id="title" value="<%=title %>" /></div>
				<div><label for="uid">작성자</label><input type="text" name="uid" id="uid" value="<%=uid %>" /></div>
				<div><label for="contents" class="dragup">본문</label><textarea name="contents" id="contents" cols="65" rows="15"><%=contents %></textarea></div>
				<div><label></label><button type="submit">수정완료</button><button type="reset">다시입력</button></div>
				<input type="hidden" name="bdno" value="<%=bdno %>" />
			</form>
		</div> <!-- content -->
		
		<div>
			<hr />
			<p id="copy">Copyright &copy; 2013 JINn. All right reserved.</p>
		</div> <!-- footer -->		
	</body>
</html>
